<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>

<body>
    <div id="app">
        <input type="text" v-model="pName">
        <button @click="addData">添加数据</button>
        <br>
        <table>
            <tr>
                <td>编号</td>
                <td>名称</td>
                <td>创建时间</td>
                <td>操作</td>
            </tr>
            <tr>
                <td colspan="4" v-if="list.length == 0">当前列表里没有数据</td>
            </tr>
            <tr v-for="item in list">
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.ctime}}</td>
                <td>
                    <a href="javascript:void(0)" @click="">删除</a>
                </td>
            </tr>
        </table>
    </div>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                id: '',
                pName: "",
                list: [
                    {
                        id: 1,
                        name: "奔驰",
                        ctime: new Date()
                    },
                    {
                        id: 2,
                        name: "宝马",
                        ctime: new Date()
                    },
                    {
                        id: 3,
                        name: "奇瑞",
                        ctime: new Date()
                    },
                ]
            },
            methods: {
                addData: function () {
                    var index = this.list.length
                    var person = {
                        id: this.list[index-1].id + 1,
                        name: this.pName,
                        ctime: new Date()
                    }
                    this.list.push(person);
                    this.pName = "";
                }
            }
        })
    </script>
</body>

</html>